﻿using EFModel;
using IServices;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Y2.Filters;

namespace Y2.Controllers
{
    [LoginFilter]
    public class RoleController : Controller
    {
        static public int id1;
        private readonly IRole he;
        public RoleController(IRole he)
        {
            this.he = he;
        }
        public IActionResult Role()
        {
            return View();
        }

        public IActionResult Roleqx(int? id)
        {
            ViewBag.RoleID = id;
            ViewBag.id = HttpContext.Session.GetString("id");
            return View();
        }
        //角色查询
        public async Task<IActionResult> result(int currentPage, int pageSize)
        {
            return Content(JsonConvert.SerializeObject(await he.result(currentPage, pageSize)));
        }
        //角色添加
        public async Task<int> Insert(Role role)
        {
            return await he.Insert(role);
        }
        //角色删除
        public async Task<int> Delt(Role role)
        {
            return await he.Delt(role);
        }
        //当前角色查询
        public async Task<IActionResult> Que(int id)
        {
            return Content(JsonConvert.SerializeObject(await he.Que(id)));
        }
        //角色权限查询
        public async Task<IActionResult> Quer(int pid)
        {
            return Content(JsonConvert.SerializeObject(await he.Quer(pid)));
        }
        //删除当前角色所有权限
        public async Task<int> Delts(int id)
        {
            return await he.Delts(id);
        }
        //添加角色权限
        public async Task<int> Inserts(int rid, int i)
        {
            return await he.Inserts(rid,i);
        }
        //修改角色权限
        public async Task<int> Update(Role role)
        {
            return await he.Update(role);
        }
    }
}
